/*
 * 上海远境文化传媒有限公司 版权所有
 */
package controllers;

import ext.dbutils.DBUtils;
import org.apache.commons.dbutils.ResultSetHandler;
import play.Logger;
import play.mvc.Controller;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 健康检查.
 */
public class HealthChecks extends Controller {

    public static void index() {

        try {
            Integer result = DBUtils.queryRunner().query("select 1 from dual", new ResultSetHandler<Integer>() {
                @Override
                public Integer handle(ResultSet rs) throws SQLException {
                    if (rs.next()) {
                        return rs.getInt(1);
                    }
                    return 0;
                }
            });
            if (result != 1) {
                error(400, "数据库查询值不正确.");
            }
        } catch (SQLException e) {
            Logger.error(e, "LOG83160: 健康检查出错");
            error(400, "数据库出错:" + e.getMessage());
        }

        renderText("OK");

    }
}
